package cn.bone.demo;

import cn.bone.demo.util.FastJsonConverterFactory;
import com.alibaba.fastjson.JSON;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;

import java.io.IOException;

/**
 * Created by MD-01 on 2016/12/30.
 */
public class Main {

    public static void main(String[] args){
        ApiService service = new Retrofit.Builder()
                .baseUrl("http://116.62.5.195:8888/xmd_djk/mobile/")
                //使用fastjson的解析
                .addConverterFactory(FastJsonConverterFactory.create())
                .build()
                .create(ApiService.class);
        Call<User> login = service.login("cry", "123456");
       /*
        //异步
        login.enqueue(new Callback<User>() {
            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                System.out.println(response.code());
                System.out.println(JSON.toJSONString(response.body()));
            }
            @Override
            public void onFailure(Call<User> call, Throwable t) {
                System.out.println("接口请求失败");
            }
        });*/

        //同步
        try {
            Response<User> response = login.execute();
            System.out.println(response.code());
            System.out.println(JSON.toJSONString(response.body()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
